@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>网站管理</li>
            <li class="active">运营管理</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
            销售统计
        </div>
        <div class="row wrapper">
            <form class="form-horizontal" method="get"
                  action="{{ admin_action('Web\CooController@index') }}">

                <div class="form-group">
                    <label class="control-label col-sm-1">开始时间:</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control datetimepicker" name="start_at"
                               value="{{ $query['start_at'] }}" placeholder="请选择开始时间" >
                    </div>
                    <label class="control-label col-sm-1">结束时间:</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control datetimepicker" name="end_at"
                               value="{{$query['end_at']}}" placeholder="请选择结束时间" >
                    </div>
                    <label class="control-label col-sm-1">定点时间:</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control datetimepicker" name="time"
                               value="{{$query['time']}}" placeholder="请选择定点时间" >
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label col-sm-1">机构类别:</label>
                    <div class="col-sm-2">
                        <select onchange="codeChange(this,document.getElementById('dept_code'))" name="org_code" class="form-control select2">
                            <option value="">----请选择机构----</option>
                            @foreach( $org as $org_code_cate)
                                @if($org_code_cate->code == $query['org_code'])
                                    <option value="{{$org_code_cate->code }}"
                                            selected="selected">{{ $org_code_cate->name }}</option>
                                @else
                                    <option value="{{ $org_code_cate->code }}">{{ $org_code_cate->name  }}</option>
                                @endif
                            @endforeach
                        </select>
                    </div>
                    <label class="control-label col-sm-1">部门类别:</label>
                    <div class="col-sm-2">
                        <select name="dept_code" id="dept_code" class="form-control select">
                            <option value="">----请选择部门----</option>
                            @if(!empty($dept))
                                @foreach( $dept as $dept_code_cate)
                                    @if($dept_code_cate->code == $query['dept_code'])
                                        <option value="{{$dept_code_cate->code }}"
                                                selected="selected">{{ $dept_code_cate->name }}</option>
                                    @endif
                                @endforeach
                            @endif
                        </select>
                    </div>
                    <div class="col-sm-5 text-right">
                            <span class="input-group-btn">
                              <button class="btn btn-sm btn-default" type="submit">查询</button>
                            </span>
                    </div>
                </div>
            </form>
        </div>
        <div class="table-responsive">
            <table class="table table-striped b-t b-light">
                <thead>
                <tr>
                    <th>姓名</th>
                    <th>期间的注册人数</th>
                    <th>新客户投资数</th>
                    <th>期间的交易量</th>
                    <th>到期量</th>
                    <th>时点存量</th>
                </tr>
                </thead>
                <tbody>
                @forelse ($lists as $item)
                    <tr>
                        <td>{{$item->name}}</td>
                        <td>{{empty($item->invite_num)?'0':$item->invite_num}}人</td>
                        <td>{{empty($item->valid_num)?'0':$item->valid_num}}人</td>
                        <td>{{empty($item->invite_money)?'0.00':$item->invite_money}}</td>
                        <td>{{empty($item->repayment_money)?'0.00':$item->repayment_money}}</td>
                        <td>{{empty($item->wait_payment_money)?'0.00':$item->wait_payment_money-$item->is_payment_money}}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="text-center">没有找到销售统计记录</td>
                    </tr>
                @endforelse
                </tbody>
            </table>
        </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-12 text-right text-center-xs">
                    {!! $links !!}
                </div>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
    <script>
        /**
         * 选择部门
         */
        function codeChange(org_code,dept_code){

            var oc,dc;
            var i,j;
            oc=org_code.value;
            dc=dept_code.value;
            dept_code.length =1;
//            if(dept_code.length ==2){
//                alert(dc);
//                $('#dept_code').html('<option value="">----请选择部门----</option>');
//            };
            if (oc == '0') return;
            $.get('/admin/web/coo/sale/getdeptcode/'+oc+'',function(data){
                if (typeof (data[oc]) == 'undefined') return;
                for (i = 0; i < data[oc].length; i++) {
                    j = i + 1;
                    dept_code.options[j] = new Option();
                    dept_code.options[j].text = data[oc][i].name;
                    dept_code.options[j].value = data[oc][i].code;
                }
                dept_code.options[0].text = "----请选择部门----";
                dept_code.options[0].value = "";
            })

        }
    </script>
    <script>
        /**
         * 格式化时间
         *
         * @param now
         * @returns {string}
         */
        function formatDate(now) {
            var year = now.getFullYear();
            var month = now.getMonth() + 1;
            var date = now.getDate();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }
        ;
    </script>
@endsection
